#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<unordered_map>
#include<unordered_set>
#define int long long 
#define x first 
#define y second 
using namespace std;
const int N = 1e5 + 10;
int flag = 0;
int sum = 0;
void solve()
{
    int n,m,a,b;
    cin >> n >> m >> a >> b;
    while(m--)
    {
        int k;
        cin >> k;
        vector<int> arr(k+1);
        for(int i = 1; i <= k; i++) cin >> arr[i];
        for(int j = 1; j <= k; j++)
        {
            if(arr[j] == a)   flag = 1;
            if(flag == 1 && arr[j] == b) flag = 2;
        }
        if(flag == 2) sum ++;
    }
    cout << sum << endl;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int t = 1;
    while(t--) solve();
    return 0;
}